<template>
  <div class="Sale-updata">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="销售姓名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>

      <el-form-item label="销售年龄">
        <el-input v-model="form.age"></el-input>
      </el-form-item>

      <el-form-item label="销售性别">
        <el-radio-group v-model="form.gender">
          <el-radio label="男"></el-radio>
          <el-radio label="女"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="销售电话">
        <el-input v-model="form.tell"></el-input>
      </el-form-item>

        <el-button type="primary" @click="sure">确认修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {createNamespacedHelpers} from 'vuex';
const {mapActions:SaleMapActions} = createNamespacedHelpers("sales");

export default {
  data(){
    return{
      form:{
        username:'',
        age:'',
        gender:'',
        tell:'',
      }
    }
  },
  computed:{},
  async created(){
    const _id = this.$route.params._id;
    // console.log(_id);
    const data = await this.getUpdataOneAsync(_id);
    this.form = data.data[0];
    // console.log(data);
  },
  methods:{
    ...SaleMapActions(["getUpdataOneAsync","SureupdataOneAsync"]),
    async sure(){
      const data = await this.SureupdataOneAsync(this.form);
      if(data.status){
        this.$message({
          message: '修改成功',
          type: 'success'
        });
        this.$router.push('/SalesList');
      }else{
        this.$message.error('修改失败');
      }
    }
  },
}
</script>

<style>
  .sale-updata{
    width: 400px;
    margin: 20px auto; 
}
</style>